<?php /*a:2:{s:63:"/www/wwwroot/cloud_boss/application/admin/view/order/index.html";i:1584974739;s:64:"/www/wwwroot/cloud_boss/application/admin/view/public/basic.html";i:1573743224;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title><?php echo htmlentities((isset($title) && ($title !== '')?$title:'重庆优合一众')); ?></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/plugs/layui/css/layui.css" media="all"/>
    <!--<link rel="stylesheet" href="/static/layuicms/css/index.css" media="all" />-->
    
<link rel="stylesheet" href="/static/css/admin/public.css" media="all"/>

</head>
<body class="<?php echo htmlentities((isset($body) && ($body !== '')?$body:'childrenBody')); ?>">

<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input name" placeholder="请输入订单编号"/>
                </div>
                <a class="layui-btn search_btn" data-type="reload">搜索</a>
            </div>

            <?php if(auth("$thisClass/del")): ?>
            <div class="layui-inline">
                <a class="layui-btn layui-btn-danger layui-btn-sm delAll_btn">批量删除</a>
            </div>
            <?php endif; ?>
        </form>
    </blockquote>
    <table id="userList" lay-filter="userList"></table>

    <script type="text/html" id="checkStatus">
        <input type="checkbox" name="{{d.meal_id}}" value="{{d.status}}" lay-skin="switch" lay-text="正常|异常" lay-filter="modifyStatus" {{ d.status== 1 ? 'checked' : '' }}>
    </script>

    <!--操作-->
    <script type="text/html" id="userListBar">

        {{# if(d.pay_way==3 && d.pay_status==1){ }}
            <a class="layui-btn layui-btn-sm" lay-event="confirmPay">确认支付</a>
        {{# } }}


        <!--<?php if(auth("$thisClass/edit")): ?>-->
        <!--<a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>-->
        <!--<?php endif; ?>-->

        <!--<?php if(auth("$thisClass/del")): ?>-->
        <!--<a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</a>-->
        <!--<?php endif; ?>-->

    </script>
</form>

<script type="text/javascript" src="/static/plugs/jquery/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="/static/plugs/layui/layui.js"></script>
<script type="text/javascript" src="/static/admin.js"></script>
<script type="text/javascript" src="/static/js/admin/api.js"></script>

<script>
    layui.use(['laydate', 'form', 'layer', 'table', 'laytpl'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            // laytpl = layui.laytpl,
            table = layui.table;
            // laydate = layui.laydate;


        // 列表
        var tableIns = table.render({
            elem: '#userList',
            url: '<?php echo url("$thisClass/index"); ?>?type=ajax',
            cellMinWidth: 95,
            page: true,
            height: "full-125",
            limits: [10, 15, 20, 25],
            limit: 20,
            id: "userListTable",
            cols: [[
                {type: "checkbox", fixed: "left", width: 50},
                {field: 'order_sn', title: '订单编号', minWidth: 100, align: "center"},
                {field: 'company_id', title: '用户ID', minWidth: 100, align: "center"},
                {field: 'order_type_name', title: '订单类型', minWidth: 100, align: "center"},
                {field: 'order_status_name', title: '订单状态', minWidth: 100, align: "center"},
                {field: 'order_has_pay_money', title: '支付金额', align: 'center'},
                {field: 'pay_way_name', title: '支付类型', align: 'center'},
                {field: 'pay_status_name', title: '支付状态', align: 'center'},
                {field: 'create_time', title: '下单时间', align: 'center', minWidth: 150},

                /**<?php if(auth("$thisClass/edit") || auth("$thisClass/del") || auth("$thisClass/edit_password")): ?>**/
                {title: '操作', minWidth: 175, templet: '#userListBar', fixed: "right", align: "center"}
                /**<?php endif; ?>**/
            ]]
        });

        // 搜索【此功能需要后台配合，所以暂时没有动态效果演示】
        $(".search_btn").on("click", function () {

            if ($(".searchVal").val() != '') {
                //执行重载
                table.reload('userListTable', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        //传参数
                        select: {
                            order_sn: $(".name").val(),
                        }

                    }
                });
                layer.msg('查询成功');
            } else {
                layer.msg("请输入搜索的内容");
            }
        });

        // 添加
        function addUser(edit) {
            var index = layui.layer.open({
                title: "添加套餐",
                type: 2,
                content: '<?php echo url("$thisClass/add"); ?>',
                success: function (layero, index) {
                    var body = layui.layer.getChildFrame('body', index);
                    if (edit) {
                        body.find(".userName").val(edit.userName);  //登录名
                        body.find(".userEmail").val(edit.userEmail);  //邮箱
                        body.find(".userSex input[value=" + edit.userSex + "]").prop("checked", "checked");  //性别
                        body.find(".userGrade").val(edit.userGrade);  //会员等级
                        body.find(".userStatus").val(edit.userStatus);    //用户状态
                        body.find(".userDesc").text(edit.userDesc);    //用户简介
                        form.render();
                    }
                    setTimeout(function () {
                        layui.layer.tips('点击此处返回套餐列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    }, 500)
                }
            })
            layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize", function () {
                layui.layer.full(index);
            })
        }

        // 编辑
        function editUser(edit) {
            var index = layui.layer.open({
                title: "编辑套餐",
                type: 2,
                content: '<?php echo url("$thisClass/edit"); ?>?id=' + edit.meal_id,
                success: function (layero, index) {
                    var body = layui.layer.getChildFrame('body', index);
                    setTimeout(function () {
                        layui.layer.tips('点击此处返回菜单列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    }, 500)
                }
            })
            layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize", function () {
                layui.layer.full(index);
            })
        }

        // 确认支付
        function confirmPay(data) {
            layer.confirm('确定修改订单为已支付吗？', {icon: 3, title: '提示信息'}, function (index) {
                $.get('<?php echo url("$thisClass/confirmPay"); ?>', {
                    order_id: data.order_id
                }, function (data) {
                    console.log(data);
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1}, function () {
                            tableIns.reload();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                })
            })
        }

        $(".addNews_btn").click(function () {
            addUser();
        })

        //批量删除
        $(".delAll_btn").click(function () {
            var checkStatus = table.checkStatus('userListTable'),
                data = checkStatus.data,
                menuId = [];
            if (data.length > 0) {
                for (let i in data) {
                    menuId.push(data[i].order_id);
                }
                layer.confirm('确定删除选中的数据？', {icon: 3, title: '提示信息'}, function (index) {
                    console.log('ss',menuId);
                    $.get('<?php echo url("$thisClass/del"); ?>', {
                        id: menuId  //将需要删除的menuId作为参数传入
                    }, function (data) {
                        console.log(data);
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1}, function () {
                                tableIns.reload();
                            });
                        } else {
                            layer.msg(data.msg, {icon: 2});
                        }
                    })
                })
            } else {
                layer.msg("请选择需要删除的数据");
            }
        })

        // 监听状态操作
        form.on('switch(modifyStatus)', function (obj) {
            console.log(this.name);
            $.get('<?php echo url("$thisClass/status"); ?>', {
                id: this.name  //将需要删除的newsId作为参数传入
            }, function (data) {
                console.log(data);
                if (data.code == 0) {
                    layer.msg(data.msg, {icon: 1});
                } else {
                    layer.msg(data.msg, {icon: 2}, function () {
                        tableIns.reload();
                        layer.close(index);
                    });
                }
            }).error(function () {
                layer.msg('系统错误，请稍后再试', {icon: 2}, function () {
                    tableIns.reload();
                });
            });
            return false;
        });

        // 列表操作
        table.on('tool(userList)', function (obj) {
            var layEvent = obj.event,
                data = obj.data;

            if (layEvent === 'edit') { //编辑
                editUser(data);
            } else if (layEvent == 'confirmPay') {
                confirmPay(data);
            } else if (layEvent === 'speciAdd') {
                speciAdd(data);
            } else if (layEvent === 'edit_password') {
                edit_passwordUser(data);
            } else if (layEvent === 'usable') { //启用禁用
                var _this = $(this),
                    usableText = "是否确定禁用此用户？",
                    btnText = "已禁用";
                if (_this.text() == "已禁用") {
                    usableText = "是否确定启用此用户？",
                        btnText = "已启用";
                    console.log('3333333333');
                    console.log(data);
                }
                layer.confirm(usableText, {
                    icon: 3,
                    title: '系统提示',
                    cancel: function (index) {
                        console.log('1111111111');
                        layer.close(index);
                    }
                }, function (index) {
                    _this.text(btnText);
                    layer.close(index);
                }, function (index) {
                    layer.close(index);
                });
            } else if (layEvent === 'del') { //删除
                layer.confirm('确定删除此用户？', {icon: 3, title: '提示信息'}, function (index) {
                    $.get('<?php echo url("$thisClass/del"); ?>', {
                        id: data.meal_id  //将需要删除的newsId作为参数传入
                    }, function (data) {
                        console.log(data);
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1}, function () {
                                tableIns.reload();
                                layer.close(index);
                            });
                        } else {
                            layer.msg(data.msg, {icon: 2});
                        }
                    })
                });
            }
        });

    })
</script>

</body>
</html>